package uicgas.station;

import org.apache.log4j.Logger;

import uicgas.tools.LogHelper;

public class StartGasStation
{
	private static final Logger LOGGER = LogHelper
			.getLogger(StartGasStation.class);

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		int port_pumps;
		int port_registers;
		String recomm_password;
		StationLogic gasStation;
		//		boolean loop = true;

		if (args.length < 3)
		{
			//not enough arguments
			System.out
					.println("USAGE: StartGasStation <pump port number> <register port number> <recommissioning password>");
			System.exit(0);
		}
		else
		{
			try
			{
				long begin = System.currentTimeMillis();

				//parse out arguments
				port_pumps = Integer.parseInt(args[0]);
				port_registers = Integer.parseInt(args[1]);
				recomm_password = args[2];

				LOGGER.debug("Begin to create StationLogic... ");
				//create StationLogic
				gasStation = new StationLogic(port_pumps, port_registers,
						recomm_password);
				LOGGER.debug("End to create StationLogic. ");

				//start servers
				LOGGER.debug("Begin to start start PumpServer... ");
				gasStation.startPumpServer();
				LOGGER.debug("End to start start PumpServer... ");

				LOGGER.debug("Begin to start start RegisterServer... ");
				gasStation.startRegisterServer();
				LOGGER.debug("End to start start RegisterServer... ");

				LOGGER.debug("===============================================");
				LOGGER.debug("Gas Station is started in ["
						+ (System.currentTimeMillis() - begin)
						+ "] milliseconds. ");
				LOGGER.debug("===============================================");

			}
			catch (NumberFormatException n)
			{
				System.out
						.println("USAGE: StartGasStation <port number> <register port number> <recommissioning password>");
				System.out.println("port numbers must be an integers");

			}
		}
	}

}
